<?php
/**
 * 单个值城市搜索条件
 * Enter description here ...
 * @author nijn
 *
 */
class CitySearchCondition extends CActiveRecordBehavior{
	/**
	 * 每级所对应的字段
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $citys = array();
	public $with = array();
	public $searchCity;
	
	public function beforeFind($event) {
		$this->citySearch();
	}
	
	public function citySearch() {
		$owner = $this->getOwner();
		if (empty($this->searchCity)) return $owner;
		
		
		$criteria = $owner->getDbCriteria();
		$criteria->with = $this->with;
		$city = CommonDistrict::model()->findByPk($this->searchCity);
		
		$key = $city->layer - 1;
		$attribute = !empty($this->citys[$key]) ? $this->citys[$key] : $this->citys[0] ;
		
		$criteria->compare($attribute, $this->searchCity);
		return $owner;
	}
}

?>